package edu.ccut.saturn.component.loader.node;

/**
 * 用于解析logic组件配置文件中“结束”结点的加载类。
 * <p>继承了<code>NodeInfoLoader</code>,并实现了<code>loadNode</code>方法。<p>
 * 
 * @author 谷钰
 * 
 * @version 1.0 2008.8.18
 * 
 * @see <code>EndNodeInfo</code>
 */
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;
import org.osgi.framework.Bundle;

import edu.ccut.saturn.component.INodeInfo;
import edu.ccut.saturn.component.SaturnComponentException;
import edu.ccut.saturn.component.impl.node.EndNodeInfo;

public class EndNodeInfoLoader extends NodeInfoLoader {

	public static final String KEY_NODETYPE_END = "end";

	@SuppressWarnings("unchecked")
	public List<INodeInfo> loadNode(Element root, Bundle bundle)
			throws SaturnComponentException {

		List<Element> endElements = root.elements(KEY_NODETYPE_END);
		List<INodeInfo> endNodeInfos = new ArrayList<INodeInfo>(endElements
				.size());

		for (Element endElement : endElements) {
			String id = endElement.attributeValue(KEY_NODE_ID).trim();
			String x = endElement.attributeValue(KEY_NODE_X).trim();
			String y = endElement.attributeValue(KEY_NODE_Y).trim();
			String name = endElement.elementText(KEY_NODE_NAME).trim();
			String description = endElement
					.elementTextTrim(KEY_NODE_DESCRIPTION);

			logger.debug("  load end node id = \"" + id + "\" name = \"" + name + "\" description = \"" + description + "\"");
			
			EndNodeInfo endNodeInfo = new EndNodeInfo(id, name, description, x, y);
			endNodeInfos.add(endNodeInfo);
		}

		return endNodeInfos;
	}

}
